package autocode

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
    autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type ProgramJoinInfoApi struct {
}

var programJoinInfoService = service.ServiceGroupApp.AutoCodeServiceGroup.ProgramJoinInfoService


// CreateProgramJoinInfo 创建ProgramJoinInfo
// @Tags ProgramJoinInfo
// @Summary 创建ProgramJoinInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ProgramJoinInfo true "创建ProgramJoinInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /programJoinInfo/createProgramJoinInfo [post]
func (programJoinInfoApi *ProgramJoinInfoApi) CreateProgramJoinInfo(c *gin.Context) {
	var programJoinInfo autocode.ProgramJoinInfo
	_ = c.ShouldBindJSON(&programJoinInfo)
	if err := programJoinInfoService.CreateProgramJoinInfo(programJoinInfo); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteProgramJoinInfo 删除ProgramJoinInfo
// @Tags ProgramJoinInfo
// @Summary 删除ProgramJoinInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ProgramJoinInfo true "删除ProgramJoinInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /programJoinInfo/deleteProgramJoinInfo [delete]
func (programJoinInfoApi *ProgramJoinInfoApi) DeleteProgramJoinInfo(c *gin.Context) {
	var programJoinInfo autocode.ProgramJoinInfo
	_ = c.ShouldBindJSON(&programJoinInfo)
	if err := programJoinInfoService.DeleteProgramJoinInfo(programJoinInfo); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteProgramJoinInfoByIds 批量删除ProgramJoinInfo
// @Tags ProgramJoinInfo
// @Summary 批量删除ProgramJoinInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除ProgramJoinInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /programJoinInfo/deleteProgramJoinInfoByIds [delete]
func (programJoinInfoApi *ProgramJoinInfoApi) DeleteProgramJoinInfoByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := programJoinInfoService.DeleteProgramJoinInfoByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateProgramJoinInfo 更新ProgramJoinInfo
// @Tags ProgramJoinInfo
// @Summary 更新ProgramJoinInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ProgramJoinInfo true "更新ProgramJoinInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /programJoinInfo/updateProgramJoinInfo [put]
func (programJoinInfoApi *ProgramJoinInfoApi) UpdateProgramJoinInfo(c *gin.Context) {
	var programJoinInfo autocode.ProgramJoinInfo
	_ = c.ShouldBindJSON(&programJoinInfo)
	if err := programJoinInfoService.UpdateProgramJoinInfo(programJoinInfo); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindProgramJoinInfo 用id查询ProgramJoinInfo
// @Tags ProgramJoinInfo
// @Summary 用id查询ProgramJoinInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocode.ProgramJoinInfo true "用id查询ProgramJoinInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /programJoinInfo/findProgramJoinInfo [get]
func (programJoinInfoApi *ProgramJoinInfoApi) FindProgramJoinInfo(c *gin.Context) {
	var programJoinInfo autocode.ProgramJoinInfo
	_ = c.ShouldBindQuery(&programJoinInfo)
	if err, reprogramJoinInfo := programJoinInfoService.GetProgramJoinInfo(programJoinInfo.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reprogramJoinInfo": reprogramJoinInfo}, c)
	}
}

// GetProgramJoinInfoList 分页获取ProgramJoinInfo列表
// @Tags ProgramJoinInfo
// @Summary 分页获取ProgramJoinInfo列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocodeReq.ProgramJoinInfoSearch true "分页获取ProgramJoinInfo列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /programJoinInfo/getProgramJoinInfoList [get]
func (programJoinInfoApi *ProgramJoinInfoApi) GetProgramJoinInfoList(c *gin.Context) {
	var pageInfo autocodeReq.ProgramJoinInfoSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := programJoinInfoService.GetProgramJoinInfoInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
